Release 10.1A: OpenEdge Development:
Progress Dynamics Advanced Development


Using the multiTranslation call and the translation temp-table

If you have a large number of strings that you want to translate in a single call, use the multiTranslation API call, as shown:

RUN multiTranslation IN gshTranslationManager 
    ( INPUT plAllLanguages, 
      INPUT-OUTPUT TABLE ttTranslate ). 

The multiTranslation call takes two parameters:

These are the fields in the table:

/* ***************************  Main Block  *************************** */ 
&IF DEFINED(ttTranslate) = 0 &THEN 
  DEFINE TEMP-TABLE ttTranslate NO-UNDO RCODE-INFORMATION 
  FIELD dLanguageObj        AS DECIMAL                                                   
     /* language object or 0 for login language */ 
  FIELD cLanguageName       AS CHARACTER FORMAT "X(20)":U LABEL "Language":U             
     /* language name if known */ 
  FIELD cObjectName         AS CHARACTER FORMAT "X(40)":U LABEL "Object Name":U          
     /* object name or blank for all */ 
  FIELD lGlobal             AS LOGICAL   FORMAT "YES/NO":U LABEL "Global":U              
     /* yes = global translation, no = specific object (if not blank) */ 
  FIELD cWidgetType         AS CHARACTER FORMAT "X(20)":U LABEL "Widget Type":U          
     /* widget type, e.g. text, button, etc. */ 
  FIELD cWidgetName         AS CHARACTER FORMAT "X(40)":U LABEL "Widget Name":U          
     /* widget name or if type is text, text to translate */ 
  FIELD hWidgetHandle       AS HANDLE                                                    
     /* handle of widget if known / required */ 
  FIELD iWidgetEntry        AS INTEGER   FORMAT "9":U     LABEL "Element":U              
     /* widget entry, used for radio-sets, etc. */ 
  FIELD lDelete             AS LOGICAL   FORMAT "YES/NO":U LABEL "Delete":U              
     /* yes = global translation, no = specific object (if not blank) */ 
  FIELD cTranslatedLabel    AS CHARACTER FORMAT "X(30)":U  
     LABEL "Translated Label":U    /* translated label */ 
FIELD cOriginalLabel      AS CHARACTER FORMAT "X(30)":U LABEL "Original 
Label":U       
     /* original untranslated label */ 
  FIELD cTranslatedTooltip  AS CHARACTER FORMAT "X(40)":U  
     LABEL "Translated Tooltip":U  /* translated tooltip */ 
  FIELD cOriginalTooltip    AS CHARACTER FORMAT "X(40)":U  
     LABEL "Original Tooltip":U    /* original untranslated tooltip */ 
  INDEX key1 AS UNIQUE PRIMARY dLanguageObj cObjectName cWidgetType 
cWidgetName  
     hWidgetHandle iWidgetEntry 
  INDEX key2 cLanguageName cObjectName cWidgetType cWidgetName iWidgetEntry 
  INDEX key3 cObjectName cWidgetType cWidgetName iWidgetEntry 
  INDEX key4 cWidgetName iWidgetEntry cObjectName cWidgetType 
  . 
  &GLOBAL-DEFINE ttTranslate 
&ENDIF 

These fields should be familiar to you if you have seen the parameter list for getTranslation.

To use the Translation temp-table, first define it in the custom super procedure and then populate it:

  1. Include the definition in the Definitions section of browsercustom.p, as shown:
  2.  {af/app/aftttranslate.i} 
    

  3. Populate the table in createBrowsePopupMenu to pass it in to multiTranslation. Define a variable with the text strings you need, and a counter variable to walk through them, as shown:
  4. DEFINE VARIABLE cStrings            AS CHARACTER  NO-UNDO 
            INIT "Move Columns,Sort Columns,Save Browser Settings,Reset Browser 
    Settings,Exit". 
    DEFINE VARIABLE iString             AS INTEGER    NO-UNDO. 
    

  5. Populate the temp-table with records for each of the strings needing translation, as shown:
  6. DO iString = 1 TO NUM-ENTRIES(cStrings): 
        CREATE ttTranslate. 
        ASSIGN ttTranslate.dLanguageObj = 0   /* Use the login language */ 
               ttTranslate.cObjectName = "" 
               ttTranslate.lGlobal = NO 
               ttTranslate.cWidgetType = "TEXT" 
               ttTranslate.cWidgetName = ENTRY(iString, cStrings). 
    END. 
    

  7. Pass this to the API call, as shown:
  8. RUN multiTranslation IN gshTranslationManager 
            (INPUT NO,    /* Not for all languages */ 
             INPUT-OUTPUT TABLE ttTranslate). 
    

    The same temp-table is returned with the cTranslatedLabel field filled with the translation. If the current language is the original language or if there is no translation for an item, then nothing is returned in the cTranslatedLabel field. Therefore you must check for this and use the original text string in that case, as shown:

    /* If the current language is the original language or one for which 
       there are no translations, then cTranslatedLabel is not set, so 
       fall back on the original text. */ 
      FOR EACH ttTranslate: 
          IF ttTranslate.cTranslatedLabel = "" THEN 
             ttTranslate.cTranslatedLabel = cWidgetName. 
      END. 
    

  9. Retrieve the appropriate temp-table record for each of the menu items and use the translation for the label. Note that they will not (likely) come back in the order in which you created them because there’s no sequence assigned (as in the example above), as shown:
  10. FIND ttTranslate WHERE ttTranslate.cWidgetName = "Move Columns". 
    CREATE MENU-ITEM hColsMovableItem 
        ASSIGN  PARENT      = hPopupMenu 
                LABEL       = ttTranslate.cTranslatedLabel /* "&Move Columns" */ 
                NAME        = "ColsMovable" 
                TOGGLE-BOX  = TRUE 
                CHECKED     = FALSE. 
    

  11. After you are done using the temp-table, empty it, as shown:
  12. EMPTY TEMP-TABLE ttTranslate. 
    

  13. Save and compile the modifications to browsercustom.p, delete the current running instance of the super procedure in the Procedures ProTool, and return your test window. Now you see the translated strings, because you are logged in as a French user, as shown:

The Localization Manager itself uses translatePhrase and the other API calls here to translate titles, labels, and substitution arguments in messages. If you define text translations for these types of strings in your application, they will be translated for you in all the standard places where the framework handles translations. You can use the same calls as you did here to translate other text that the framework does not take care of for you.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095